package com.jinxiangyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinxiangyang.domain.OrderDetail;
import com.jinxiangyang.domain.OrderInfo;
import com.jinxiangyang.domain.PaymentInfo;
import com.jinxiangyang.domain.vo.OrderSalesVo;
import com.jinxiangyang.domain.vo.OrderVo;
import com.jinxiangyang.mapper.OrderDetailMapper;
import com.jinxiangyang.mapper.OrderInfoMapper;
import com.jinxiangyang.mapper.PaymentInfoMapper;
import com.jinxiangyang.service.OrderDetailService;
import com.jinxiangyang.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinxiangyang.service.PaymentInfoService;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

import static com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils.eq;

/**
 * <p>
 * 订单表 订单表 服务实现类
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
    @Autowired
    public OrderInfoMapper orderInfoMapper;
    @Autowired
    public OrderDetailService orderDetailService;
    @Autowired
    private PaymentInfoService paymentInfoService;

    @Override
    public  HashMap<String, Object> findOrderVo(Integer pageNumber,Integer pageSize, OrderVo orderVo){
        Page<OrderVo> orderVoPage = new Page<>(pageNumber,pageSize);
        List<OrderVo> orderByPage = orderInfoMapper.getOrderByPage(orderVoPage, orderVo);
        HashMap<String, Object> result = new HashMap<>();
        result.put("page",orderVoPage);
        result.put("noticeList",orderByPage);
        return result;
    }

    @Autowired
    private PaymentInfoMapper paymentInfoMapper;


    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Override
    public Boolean deleteOrderVo(Long id) {
        LambdaQueryWrapper<OrderInfo> queryWrapper1 = new LambdaQueryWrapper<>();
        int b1 = orderInfoMapper.delete(queryWrapper1.eq(OrderInfo::getId, id));
        LambdaQueryWrapper<OrderDetail> queryWrapper2 = new LambdaQueryWrapper<>();
        int b2 = orderDetailMapper.delete(queryWrapper2.eq(OrderDetail::getOrderId, id));
        LambdaQueryWrapper<PaymentInfo> queryWrapper = new LambdaQueryWrapper<>();
        int b3 = paymentInfoMapper.delete(queryWrapper.eq(PaymentInfo::getOrderId, id));
        if (b1==1 && b2==1 && b3==1){
            return true;
        }
        return false;
    }

    @Override
    public List<OrderSalesVo> getMonthlySales() {
        return paymentInfoMapper.getMonthlySales();
    }
}
